package com.kly.config;

import com.kly.manager.websocket.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import javax.annotation.Resource;

/**
 * @author admin
 * @date 2025/3/21
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private WsHandShakeInterceptor wsHandShakeInterceptor;

    @Resource
    private PictureEditHandler pictureEditHandler;

    @Resource
    private PictureCommentHandler pictureCommentHandler;

    @Resource
    private WsCommentHandShakeInterceptor wsCommentHandShakeInterceptor;

    @Resource
    private UserChatHandler userChatHandler;

    @Resource
    private WsUserChatHandShakeInterceptor wsUserChatHandShakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(pictureEditHandler, "/ws/picture/edit")
                .addInterceptors(wsHandShakeInterceptor)
                .setAllowedOrigins("*");

        registry.addHandler(pictureCommentHandler, "/ws/picture/comment")
                .addInterceptors(wsCommentHandShakeInterceptor)
                .setAllowedOrigins("*");

        registry.addHandler(userChatHandler, "/ws/user/chat")
                .addInterceptors(wsUserChatHandShakeInterceptor)
                .setAllowedOrigins("*");
    }
}
